home *** CD-ROM | disk | FTP | other *** search
/ Financial Peace University Interactive Bonus / Financial Peace University Bonus Interactive CD-ROM.iso / pc / calculators / reality_check_new.swf / scripts / frame_102 / DoAction.as
Encoding:
Text File  |  2006-01-27  |  15.7 KB  |  518 lines

  1. function getTimeFrame(age)
  2. {
  3.    var _loc1_ = (65 - Number(age)) * 12;
  4.    return _loc1_;
  5. }
  6. function getMortgagePayment(b, n, r)
  7. {
  8.    var _loc2_ = b * (r * Math.pow(1 + r,n)) / (Math.pow(1 + r,n) - 1);
  9.    return _loc2_;
  10. }
  11. function getMortgageBalance(m, d, n, r)
  12. {
  13.    var _loc1_ = d * (Math.pow(1 + r,n) - Math.pow(1 + r,m)) / (Math.pow(1 + r,n) - 1);
  14.    return _loc1_;
  15. }
  16. function payMortgage(b, r, p, t, m)
  17. {
  18.    if(m > t)
  19.    {
  20.       m = t;
  21.    }
  22.    trace("m: " + m);
  23.    k = 1;
  24.    while(k <= m && b > 0)
  25.    {
  26.       var _loc6_ = 0;
  27.       var _loc5_ = 0;
  28.       var _loc4_ = 0;
  29.       if(b < p - b * r)
  30.       {
  31.          _loc4_ = p - (p - b * r);
  32.       }
  33.       b -= p - b * r;
  34.       if(b < 0)
  35.       {
  36.          b = 0;
  37.       }
  38.       trace("New Balance: " + k + " " + b);
  39.       k++;
  40.    }
  41.    trace("Payment Balance: " + k + " " + _loc4_);
  42.    arrResult = new Array(b,k,_loc5_,"0",_loc4_);
  43.    return arrResult;
  44. }
  45. function getMonthlyExpenses(i, h, d, s)
  46. {
  47.    trace("Income: " + i);
  48.    trace("Housing: " + h);
  49.    trace("Debt: " + d);
  50.    trace("Savings: " + s);
  51.    var _loc1_ = i - d - s - h;
  52.    trace("Monthly Expenses: " + _loc1_);
  53.    return _loc1_;
  54. }
  55. function getSavings(b, p, t)
  56. {
  57.    trace("balance (b): " + b);
  58.    trace("payment (p): " + p);
  59.    trace("months  (t): " + t);
  60.    var _loc6_ = 0.12;
  61.    var _loc7_ = 12;
  62.    var _loc2_ = _loc6_ / _loc7_;
  63.    g = 1;
  64.    while(g <= t)
  65.    {
  66.       b *= 1 + _loc2_;
  67.       b += p;
  68.       g++;
  69.    }
  70.    var _loc5_ = Math.floor(b);
  71.    trace("Savings: " + _loc5_);
  72.    return _loc5_;
  73. }
  74. function addCommas(x)
  75. {
  76.    var _loc4_ = "";
  77.    var _loc5_ = ",";
  78.    var _loc6_ = "";
  79.    if(x.indexOf("-") >= 0)
  80.    {
  81.       x = x.substring(1,x.length);
  82.       _loc6_ = "-";
  83.    }
  84.    j = 1;
  85.    while(j <= Math.ceil(x.length / 3))
  86.    {
  87.       var _loc1_ = x.length - 3 * j;
  88.       var _loc3_ = 3;
  89.       if(_loc1_ < 0)
  90.       {
  91.          _loc3_ = x.length - (j - 1) * 3;
  92.          _loc1_ = 0;
  93.       }
  94.       if(_loc1_ == 0)
  95.       {
  96.          _loc5_ = "";
  97.       }
  98.       _loc4_ = _loc5_ + x.substr(_loc1_,_loc3_) + _loc4_;
  99.       j++;
  100.    }
  101.    _loc4_ = _loc6_ + _loc4_;
  102.    return _loc4_;
  103. }
  104. function payDebt(b, p, r, n, t)
  105. {
  106.    p = _global.DebtPayment + _global.MonthlySavings + _global.MonthlyExpensesContributed + _global.ExtraJob;
  107.    while(b > 0 && m < _global.TimeFrame)
  108.    {
  109.       e = b * (1 + r / 12);
  110.       if(e < p)
  111.       {
  112.          LeftoverDebtPayment = c - e;
  113.          c = e;
  114.       }
  115.       b = e - c;
  116.       _global.Debt = b;
  117.       months += 1;
  118.       trace(z + ": (months)" + months);
  119.       trace(z + ": (c)" + c);
  120.       trace(z + ": " + _global.Debt);
  121.       z += 1;
  122.    }
  123. }
  124. _global.TimeFrame = getTimeFrame(_global.Age);
  125. trace(_global.TimeFrame);
  126. i = _global.MonthlyIncome;
  127. h = 0;
  128. d = _global.DebtPayment;
  129. s = _global.MonthlySavings;
  130. if(_global.Housing == "rent")
  131. {
  132.    if(isNaN(Number(_global.HousingPayment)) == 0)
  133.    {
  134.       h = Number(_global.HousingPayment);
  135.    }
  136. }
  137. else if(_global.Housing == "own" && isNaN(Number(_global.MortgageQty)) == 0)
  138. {
  139.    j = 1;
  140.    while(j <= _global.MortgageQty)
  141.    {
  142.       b = Number(_global["MortgageAmount" + j]);
  143.       n = 12 * Number(_global["MortgageTerm" + j]);
  144.       r = Number(_global["MortgageRate" + j]) / 100 / 12;
  145.       _global["MortgagePayment" + j] = getMortgagePayment(b,n,r);
  146.       h += _global["MortgagePayment" + j];
  147.       j++;
  148.    }
  149. }
  150. _global.MonthlyExpenses = getMonthlyExpenses(i,h,d,s);
  151. trace("Mortgages: " + _global.MortgageQty);
  152. trace("Mortgage Payment 1: " + _global.MortgagePayment1);
  153. trace("Mortgage Payment 2: " + _global.MortgagePayment2);
  154. trace("YOUR PLAN  |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
  155. if(_global.Housing == "own")
  156. {
  157.    j = 1;
  158.    while(j <= _global.MortgageQty)
  159.    {
  160.       m = 12 * (Number(_global["MortgageTerm" + j]) - Number(_global["MortgageTermRemaining" + j]));
  161.       d = Number(_global["MortgageAmount" + j]);
  162.       n = 12 * Number(_global["MortgageTerm" + j]);
  163.       r = Number(_global["MortgageRate" + j]) / 100 / 12;
  164.       t = _global.TimeFrame;
  165.       var b = getMortgageBalance(m,d,n,r);
  166.       trace("Balance: " + b);
  167.       var p = _global["MortgagePayment" + j];
  168.       trace("Payment: " + p);
  169.       m = Number(_global["MortgageTermRemaining" + j]) * 12;
  170.       _global["MortgageStatus" + j] = payMortgage(b,r,p,t,m);
  171.       trace("Mortgage Balance: " + _global["MortgageStatus" + j][0]);
  172.       j++;
  173.    }
  174. }
  175. _global.MortgagePayoffOrder = new Array();
  176. if(_global.Housing == "own")
  177. {
  178.    j = 1;
  179.    while(j <= _global.MortgageQty)
  180.    {
  181.       if(_global["MortgageStatus" + j][0] == 0 && _global["MortgageStatus" + j][1] < _global.TimeFrame)
  182.       {
  183.          var g = 1;
  184.          k = 1;
  185.          while(k < j)
  186.          {
  187.             if(_global["MortgageStatus" + k][3] != 0)
  188.             {
  189.                if(_global["MortgageStatus" + k][1] > _global["MortgageStatus" + j][1])
  190.                {
  191.                   g = _global["MortgageStatus" + k][3];
  192.                   _global["MortgageStatus" + k][3] += 1;
  193.                }
  194.                else
  195.                {
  196.                   g = _global["MortgageStatus" + k][3] + 1;
  197.                }
  198.             }
  199.             k++;
  200.          }
  201.          _global["MortgageStatus" + j][3] = g;
  202.          trace("_global.MortgageStatus" + j + "[3] : " + _global["MortgageStatus" + j][3]);
  203.       }
  204.       j++;
  205.    }
  206.    j = 1;
  207.    while(j <= _global.MortgageQty)
  208.    {
  209.       if(_global["MortgageStatus" + j][3] != 0)
  210.       {
  211.          var g = _global["MortgageStatus" + j][3];
  212.          _global.MortgagePayoffOrder[g - 1] = j;
  213.          trace("_global.MortgagePayoffOrder[(g - 1)] : " + _global.MortgagePayoffOrder[g - 1]);
  214.       }
  215.       j++;
  216.    }
  217. }
  218. var b = _global.Savings;
  219. var p = _global.MonthlySavings;
  220. trace("_global.MortgagePayoffOrder.length: " + _global.MortgagePayoffOrder.length);
  221. if(_global.MortgagePayoffOrder.length > 0)
  222. {
  223.    var t = _global["MortgageStatus" + _global.MortgagePayoffOrder[0]][1];
  224. }
  225. else
  226. {
  227.    var t = _global.TimeFrame;
  228. }
  229. b = getSavings(b,p,t);
  230. j = 0;
  231. j = 0;
  232. while(j < _global.MortgagePayoffOrder.length)
  233. {
  234.    p += _global["MortgagePayment" + _global.MortgagePayoffOrder[j]];
  235.    if(j < _global.MortgagePayoffOrder.length - 1)
  236.    {
  237.       t = _global["MortgageStatus" + _global.MortgagePayoffOrder[j + 1]][1] - _global["MortgageStatus" + _global.MortgagePayoffOrder[j]][1];
  238.       trace(_global["MortgageStatus" + _global.MortgagePayoffOrder[j + 1]][1] - _global["MortgageStatus" + _global.MortgagePayoffOrder[j]][1]);
  239.    }
  240.    else
  241.    {
  242.       t = _global.TimeFrame - _global["MortgageStatus" + _global.MortgagePayoffOrder[j]][1];
  243.       trace("TimeFrame - " + _global["MortgageStatus" + _global.MortgagePayoffOrder[j]][1]);
  244.    }
  245.    b = getSavings(b,p,t);
  246.    trace("Loop: " + j);
  247.    j++;
  248. }
  249. trace(b);
  250. _global.MortgageDebt = 0;
  251. j = 1;
  252. while(j <= _global.MortgageQty)
  253. {
  254.    if(_global["MortgageStatus" + j][0] != 0)
  255.    {
  256.       mm = Number(_global["MortgageTerm" + j]) * 12 - (Number(_global["MortgageTermRemaining" + j]) * 12 - _global.TimeFrame);
  257.       md = Number(_global["MortgageAmount" + j]);
  258.       mn = 12 * Number(_global["MortgageTerm" + j]);
  259.       mr = Number(_global["MortgageRate" + j]) / 100 / 12;
  260.       mt = _global.TimeFrame;
  261.       var mb = _global["MortgageStatus" + j][0];
  262.       trace("Balance: " + mb);
  263.       var d = mb;
  264.       var n = 1;
  265.       var r = Number(_global["MortgageRate" + j]) / 100 / 12;
  266.       var mp = getMortgagePayment(d,n,r);
  267.       trace("Payment: " + mp);
  268.       md = payMortgage(mb,mr,mp,mt,mm);
  269.       _global.MortgageDebt += mp;
  270.       trace("Mortgage Debt: " + _global.MortgageDebt);
  271.    }
  272.    j++;
  273. }
  274. _global.YourPlan = b - _global.Debt - _global.MortgageDebt;
  275. _global.YourPlan = addCommas(String(Math.round(_global.YourPlan)));
  276. trace("YOUR PLAN: " + _global.YourPlan);
  277. trace("DAVE\'S PLAN  |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
  278. _global.MonthlyExpensesAdjusted = 0;
  279. _global.MonthlyExpensesContributed = 0;
  280. if(_global.MonthlyExpenses > 0)
  281. {
  282.    _global.MonthlyExpensesAdjusted = _global.MonthlyExpenses - _global.MonthlyExpenses * 0.1;
  283.    _global.MonthlyExpensesContributed = _global.MonthlyExpenses - _global.MonthlyExpensesAdjusted;
  284. }
  285. if(_global.MonthlyExpensesContributed < 0)
  286. {
  287.    _global.MonthlyExpensesContributed = 0;
  288. }
  289. trace("MonthlyExpensesAdjusted: " + _global.MonthlyExpensesAdjusted);
  290. trace("MonthlyExpensesContributed: " + _global.MonthlyExpensesContributed);
  291. _global.ExtraJob = 750;
  292. var months = 0;
  293. _global.EmergencyFund = 0;
  294. if(_global.Debt > 0 && _global.MortgageQty > 0)
  295. {
  296.    while(_global.EmergencyFund < 1000)
  297.    {
  298.       _global.EmergencyFund = _global.EmergencyFund + _global.MonthlyExpensesContributed + _global.ExtraJob + _global.MonthlySavings;
  299.       months += 1;
  300.       trace("BEF: " + _global.EmergencyFund);
  301.       trace("month: " + months);
  302.    }
  303.    trace("Baby Emergency Fund: " + _global.EmergencyFund);
  304.    trace("Consumer Debt: " + _global.Debt);
  305.    z = 1;
  306.    if(_global.EmergencyFund > 1000)
  307.    {
  308.       EFleftover = _global.EmergencyFund - 1000;
  309.       _global.EmergencyFund = 1000;
  310.       trace("EFleftover: " + EFleftover);
  311.       p = _global.Debt;
  312.       c = EFleftover + _global.DebtPayment;
  313.       r = 0.15;
  314.       b = p;
  315.       b = b * (1 + r / 12) - c;
  316.       _global.Debt = b;
  317.       trace(z + ": (c)" + c);
  318.       trace(z + ": " + _global.Debt);
  319.       z += 1;
  320.    }
  321.    c = _global.DebtPayment + _global.MonthlySavings + _global.MonthlyExpensesContributed + _global.ExtraJob;
  322.    while(b > 0 && m < _global.TimeFrame)
  323.    {
  324.       e = b * (1 + r / 12);
  325.       if(e < c)
  326.       {
  327.          LeftoverDebtPayment = c - e;
  328.          c = e;
  329.       }
  330.       b = e - c;
  331.       _global.Debt = b;
  332.       months += 1;
  333.       trace(z + ": (months)" + months);
  334.       trace(z + ": (c)" + c);
  335.       trace(z + ": " + _global.Debt);
  336.       z += 1;
  337.    }
  338.    if(months < _global.TimeFrame)
  339.    {
  340.       b = _global.EmergencyFund;
  341.       p = c;
  342.       t = 1;
  343.       j = 0;
  344.       trace("Emergency Fund: b:" + b + " p:" + p + " t:" + t);
  345.       j = 1;
  346.       while(_global.EmergencyFund < _global.MonthlyIncome * 3 && months + j < _global.TimeFrame)
  347.       {
  348.          _global.EmergencyFund += c;
  349.          months += 1;
  350.          trace("Month: " + months);
  351.          trace("Emergency Fund: " + _global.EmergencyFund);
  352.          trace("c: " + c);
  353.          j++;
  354.       }
  355.       trace("Months:" + months);
  356.    }
  357.    b = _global.Savings;
  358.    p = 0;
  359.    t = months;
  360.    _global.Savings = getSavings(b,p,t);
  361.    if(_global.Housing == "own")
  362.    {
  363.       j = 1;
  364.       while(j <= _global.MortgageQty)
  365.       {
  366.          m = Number(_global["MortgageTerm" + j]) * 12 - Number(_global["MortgageTermRemaining" + j]) * 12;
  367.          d = Number(_global["MortgageAmount" + j]);
  368.          n = Number(_global["MortgageTerm" + j]) * 12;
  369.          r = Number(_global["MortgageRate" + j]) / 100 / 12;
  370.          t = months;
  371.          var b = getMortgageBalance(m,d,n,r);
  372.          trace("Balance: " + b);
  373.          var p = _global["MortgagePayment" + j];
  374.          trace("Payment: " + p);
  375.          m = Number(_global["MortgageTermRemaining" + j]) * 12;
  376.          _global["MortgageStatus" + j] = payMortgage(b,r,p,t,m);
  377.          trace("Mortgage Balance: " + _global["MortgageStatus" + j][0]);
  378.          j++;
  379.       }
  380.    }
  381.    if(_global.MonthlyIncome * 0.15 > _global.MonthlySavings)
  382.    {
  383.       _global.MonthlySavings = _global.MonthlyIncome * 0.15;
  384.    }
  385.    trace("Monthly Savings at 15%: " + _global.MonthlySavings);
  386.    trace("C: " + c);
  387.    if(c - _global.MonthlySavings > 0)
  388.    {
  389.       _global.MortgagePaymentExtra = c - _global.MonthlySavings;
  390.    }
  391.    else
  392.    {
  393.       _global.MortgagePaymentExtra = 0;
  394.    }
  395.    trace("Extra Mortgage Payment: " + _global.MortgagePaymentExtra);
  396.    if(_global.Housing == "own")
  397.    {
  398.       j = 1;
  399.       while(j <= _global.MortgageQty)
  400.       {
  401.          if(_global["MortgageStatus" + j][0] > 0)
  402.          {
  403.             m = Number(_global["MortgageTermRemaining" + j]) * 12 - months;
  404.             d = _global["MortgageStatus" + j][0];
  405.             n = Number(_global["MortgageTerm" + j]) * 12;
  406.             r = Number(_global["MortgageRate" + j]) / 100 / 12;
  407.             t = _global.TimeFrame - months;
  408.             var b = d;
  409.             trace("Balance: " + b);
  410.             _global["MortgagePayment" + j] += _global.MortgagePaymentExtra / _global.MortgageQty;
  411.             var p = _global["MortgagePayment" + j];
  412.             trace("Payment: " + p);
  413.             _global["MortgageStatus" + j] = payMortgage(b,r,p,t,m);
  414.             trace("Mortgage Balance: " + _global["MortgageStatus" + j][0]);
  415.          }
  416.          j++;
  417.       }
  418.    }
  419.    _global.MortgagePayoffOrder = new Array();
  420.    if(_global.Housing == "own")
  421.    {
  422.       j = 1;
  423.       while(j <= _global.MortgageQty)
  424.       {
  425.          if(_global["MortgageStatus" + j][0] == 0 && _global["MortgageStatus" + j][1] < _global.TimeFrame)
  426.          {
  427.             var g = 1;
  428.             k = 1;
  429.             while(k < j)
  430.             {
  431.                if(_global["MortgageStatus" + k][3] != 0)
  432.                {
  433.                   if(_global["MortgageStatus" + k][1] > _global["MortgageStatus" + j][1])
  434.                   {
  435.                      g = _global["MortgageStatus" + k][3];
  436.                      _global["MortgageStatus" + k][3] += 1;
  437.                   }
  438.                   else
  439.                   {
  440.                      g = _global["MortgageStatus" + k][3] + 1;
  441.                   }
  442.                }
  443.                k++;
  444.             }
  445.             _global["MortgageStatus" + j][3] = g;
  446.             trace("_global.MortgageStatus" + j + "[3] : " + _global["MortgageStatus" + j][3]);
  447.          }
  448.          j++;
  449.       }
  450.       j = 1;
  451.       while(j <= _global.MortgageQty)
  452.       {
  453.          if(_global["MortgageStatus" + j][3] != 0)
  454.          {
  455.             var g = _global["MortgageStatus" + j][3];
  456.             _global.MortgagePayoffOrder[g - 1] = j;
  457.             trace("_global.MortgagePayoffOrder[(g - 1)] : " + _global.MortgagePayoffOrder[g - 1]);
  458.          }
  459.          j++;
  460.       }
  461.    }
  462. }
  463. var b = _global.Savings;
  464. var p = _global.MonthlySavings;
  465. if(_global.MortgagePayoffOrder.length > 0)
  466. {
  467.    var t = _global["MortgageStatus" + _global.MortgagePayoffOrder[0]][1];
  468. }
  469. else
  470. {
  471.    var t = _global.TimeFrame - months;
  472. }
  473. b = getSavings(b,p,t);
  474. j = 0;
  475. while(j < _global.MortgagePayoffOrder.length)
  476. {
  477.    p += _global["MortgagePayment" + _global.MortgagePayoffOrder[j]];
  478.    if(j < _global.MortgagePayoffOrder.length - 1)
  479.    {
  480.       t = _global["MortgageStatus" + _global.MortgagePayoffOrder[j + 1]][1] - _global["MortgageStatus" + _global.MortgagePayoffOrder[j]][1];
  481.    }
  482.    else
  483.    {
  484.       t = _global.TimeFrame - _global["MortgageStatus" + _global.MortgagePayoffOrder[j]][1];
  485.    }
  486.    b = getSavings(b,p,t);
  487.    j++;
  488. }
  489. _global.MortgageDebt = 0;
  490. j = 1;
  491. while(j <= _global.MortgageQty)
  492. {
  493.    if(_global["MortgageStatus" + j][0] != 0)
  494.    {
  495.       mm = Number(_global["MortgageTerm" + j]) * 12 - (Number(_global["MortgageTermRemaining" + j]) * 12 - _global.TimeFrame);
  496.       md = Number(_global["MortgageAmount" + j]);
  497.       mn = 12 * Number(_global["MortgageTerm" + j]);
  498.       mr = Number(_global["MortgageRate" + j]) / 100 / 12;
  499.       mt = _global.TimeFrame;
  500.       var mb = _global["MortgageStatus" + j][0];
  501.       trace("Balance: " + mb);
  502.       d = mp;
  503.       n = 1;
  504.       r = Number(_global["MortgageRate" + j]) / 100 / 12;
  505.       var mp = getMortgagePayment(d,n,r);
  506.       trace("Payment: " + mp);
  507.       md = payMortgage(mb,mr,mp,mt,mm);
  508.       _global.MortgageDebt += mp;
  509.       trace("Mortgage Debt: " + _global.MortgageDebt);
  510.    }
  511.    j++;
  512. }
  513. _global.DavesPlan = b - _global.Debt - _global.MortgageDebt + _global.EmergencyFund;
  514. trace("Savings + EmergencyFund: " + _global.DavesPlan);
  515. _global.DavesPlan = addCommas(String(Math.round(_global.DavesPlan)));
  516. trace("DAVE\'S PLAN: " + _global.DavesPlan);
  517. stop();
  518.